package solution;

/**
 * @author : wenchao.long
 * @date : Created in 2024-07-02 下午 11:45 周二
 * @description :
 * 		<a href="https://leetcode.cn/problems/add-strings/description/">字符串相加</a>
 */
public class No415 {

	public static String addStrings(String num1, String num2) {
		int i = num1.length() - 1;
		int j = num2.length() - 1;
		int add = 0;
		StringBuilder res = new StringBuilder();
		while (i >= 0 || j >= 0 || add != 0) {
			int x = i >= 0 ? num1.charAt(i) - '0' : 0;
			int y = j >= 0 ? num2.charAt(j) - '0' : 0;
			int sum = x + y + add;
			res.append(sum % 10);
			add = sum / 10;
			i--;
			j--;
		}
		res.reverse();
		return res.toString();
	}

	public static void main(String[] args) {
		String s = addStrings("789", "1234");
		System.out.println(s);
	}
}
